﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Diagnostics;
using System.ComponentModel;
using BusinessObjects;
using AFSharedLibrary;
using DDW;
using System.Drawing;
using UIDesigner.DesignContainers.Bases;
using UIDesigner.SurfaceProperties.Operations;
using System.Xml.Serialization;

namespace UIDesigner.SurfaceProperties
{
    [Flags()]
    public enum SurfaceButton
    {
        None,
        Delete = 1,
        Reset = 2,
        CreateNew = 4,
        Save = 8,
        Cancel = 16,
        Mask = None | Delete | Reset | CreateNew | Save | Cancel
    }

    public class SurfaceButtonEntry
    {
        private SurfaceButton m_eSurfaceButton;
        private Control m_ctrlButtonControl;
        private int m_nCodeInsert = -1;

        public int CodeInsert
        {
            get { return m_nCodeInsert; }
            set { m_nCodeInsert = value; }
        }

        public SurfaceButton SurfaceButton
        {
            get { return m_eSurfaceButton; }
        }

        public Control ButtonControl
        {
            get { return m_ctrlButtonControl; }
        }

        public SurfaceButtonEntry(SurfaceButton eSurfaceButton, Control ctrlButtonControl)
        {
            m_eSurfaceButton = eSurfaceButton;
            m_ctrlButtonControl = ctrlButtonControl;
        }
    }

    public interface IPropertyCollectionProvider
    {
        PropertyDescriptorCollection PropertyCollection { get; }
    }

    public interface IPropertyGroup : ICloneable
    {

    }

    [XmlInclude(typeof(FormSurfaceProperties))]
    [XmlInclude(typeof(ControlSurfaceProperties))]
    public abstract class SurfacePropertiesBase : ICloneable
    {
        public abstract string Target { get; }
        public abstract object Clone();
        [System.Xml.Serialization.XmlIgnore()]
        private IBaseObjectControl m_objTargetComponent;
        [System.Xml.Serialization.XmlIgnore()]
        protected CloseActions m_eCloseActions;
        [System.Xml.Serialization.XmlIgnore()]
        protected abstract SurfaceType SurfaceType { get; }
        [System.Xml.Serialization.XmlIgnore()]
        protected CreateProperties m_objCreateProperties;
        [System.Xml.Serialization.XmlIgnore()]
        protected BindProperties m_objBindProperties;
        [System.Xml.Serialization.XmlIgnore()]
        protected DeleteProperties m_objDeleteProperties;
        [System.Xml.Serialization.XmlIgnore()]
        protected ResetProperties m_objResetProperties;
        [System.Xml.Serialization.XmlIgnore()]
        protected SaveProperties m_objSaveProperties;
        [System.Xml.Serialization.XmlIgnore()]
        protected CancelOptions m_eCancelOptions;
        [System.Xml.Serialization.XmlIgnore()]
        private string m_strName;
        private string m_strDescription;
        private bool m_bSelected;
        private bool m_bIsSystem;

        public bool IsSystem
        {
            get { return m_bIsSystem; }
            set { m_bIsSystem = value; }
        }

        public bool Selected
        {
            get { return m_bSelected; }
            set { m_bSelected = value; }
        }

        public string Description
        {
            get { return m_strDescription; }
            set { m_strDescription = value; }
        }

        public string Name
        {
            get { return m_strName; }
            set { m_strName = value; }
        }

        public void CopyTo(SurfacePropertiesBase objProperties)
        {
            objProperties.CloseActions = this.CloseActions;
            objProperties.CreateProperties = (CreateProperties) this.CreateProperties.Clone();
            objProperties.BindProperties = (BindProperties)this.BindProperties.Clone();
            objProperties.DeleteProperties = (DeleteProperties)this.DeleteProperties.Clone();
            objProperties.ResetProperties = (ResetProperties)this.ResetProperties.Clone();
            objProperties.SaveProperties = (SaveProperties)this.SaveProperties.Clone();
            objProperties.CancelOptions = m_eCancelOptions;
        }

        public CancelOptions CancelOptions
        {
            get 
            { 
                return m_eCancelOptions; 
            }
            
            set
            { 
                m_eCancelOptions = value; 
            }
        }

        [System.Xml.Serialization.XmlIgnore()]
        public IBaseObjectControl TargetComponent
        {
            get { return m_objTargetComponent; }
            set { m_objTargetComponent = value; }
        }

        public SurfaceButton SurfaceButtons
        {
            get
            {
                SurfaceButton eButtons = SurfaceButton.None;

                eButtons |= this.ResetProperties.Button;
                eButtons |= this.CreateProperties.Button;
                eButtons |= this.DeleteProperties.Button;
                eButtons |= this.SaveProperties.Button;

                if (m_eCancelOptions != CancelOptions.None)
                {
                    eButtons |= SurfaceButton.Cancel;
                }

                return eButtons;
            }
        }

        public ResetProperties ResetProperties
        {
            get 
            {
                if (m_objResetProperties == null)
                {
                    m_objResetProperties = new ResetProperties();
                }

                return m_objResetProperties; 
            }
            
            set 
            { 
                m_objResetProperties = value; 
            }
        }

        public CreateProperties CreateProperties
        {
            get 
            {
                if (m_objCreateProperties == null)
                {
                    m_objCreateProperties = new CreateProperties(ConstructorOptions.Uninitialized, CreateButtonOptions.Uninitialized);
                }

                return m_objCreateProperties; 
            }
            
            set 
            { 
                m_objCreateProperties = value; 
            }
        }

        public SaveProperties SaveProperties
        {
            get 
            {
                if (m_objSaveProperties == null)
                {
                    m_objSaveProperties = new SaveProperties();
                }

                return m_objSaveProperties; 
            }
            
            set 
            { 
                m_objSaveProperties = value; 
            }
        }

        public BindProperties BindProperties
        {
            get 
            {
                if (m_objBindProperties == null)
                {
                    m_objBindProperties = new BindProperties();
                }

                return m_objBindProperties; 
            }
            
            set 
            { 
                m_objBindProperties = value; 
            }
        }

        public DeleteProperties DeleteProperties
        {
            get 
            {
                if (m_objDeleteProperties == null)
                {
                    m_objDeleteProperties = new DeleteProperties();
                }

                return m_objDeleteProperties; 
            }
            
            set 
            {
                m_objDeleteProperties = value; 
            }
        }

        public SurfacePropertiesBase(IBaseObjectControl objTargetComponent)
        {
            m_objTargetComponent = objTargetComponent;
        }

        public CloseActions CloseActions
        {
            get 
            { 
                return m_eCloseActions; 
            }
            
            set 
            {
                m_eCloseActions = value; 
            }
        }
    }
}
